#pragma once
#include "../map/map.hpp"
#include <vector>
#include <functional>
#include <unordered_map>

class CmdCtrl{
private:
	int ctrlDice=-1;
	int lastId=0;
	std::unordered_map<std::string, std::function<bool(const std::string&,User&,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap)>> command;
public:
	CmdCtrl(){
		RegisterFunc("sold",Sold);
		RegisterFunc("preset",Preset);
		RegisterFunc("block",Block);
		RegisterFunc("robot", Robot);
		RegisterFunc("bomb", Bomb);
		RegisterFunc("query", Query);
	}
	bool RegisterFunc(std::string need,std::function<bool(const std::string&,User&,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap)> func){
		command.insert({need,func});
		return true;
	}
	void WaitInput(User& user,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap,std::vector<int>& turn);
private:
	bool Roll(User& user,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap);
	bool Step(const std::string&,User&,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap);
	static bool Print(User& user,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap,std::vector<int>& turn);
	static bool Sold(const std::string& input,User& user,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap);
	static bool Preset(const std::string& input,User& user,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap);
	static bool Block(const std::string& input,User& user,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap);
	static bool Bomb(const std::string& input,User& user,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap);
	static bool Robot(const std::string& input,User& user,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap);
	static bool Query(const std::string& input,User& user,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap);
	static void PutTool(ToolType type,int pos,User& user,std::vector<Land>& map,std::unordered_map<int,User*>& hashMap);
};

